const filledArray = require('filled-array');


function test2() {
	var fn = function(i) { 
		return (++i % 3 ? '' : 'Fizz') + (i % 5 ? '' : 'Buzz') || i;
	};


	console.log(filledArray(fn, 15));
	console.log(arrayFilled(fn, 15));
}


function test1() {
	console.log(filledArray('a'))
	// console.log(filledArray('a', -2))
	console.log('-----------------------\n')

	console.log(filledArray('x', 3))
	console.log(Array.of('x','x','x'))
	console.log(Array(3).fill('x'))

	console.log(new Array(1, 6), Array(2, 8))
	console.log(new Array(3), Array(5))
}




function arrayFilled (filler, count) {
	var result = new Array(count)
	var isFn = typeof filler === 'function'

	if(!isFn && result.fill === 'function') {
		result.fill(filler)
	}

	
	for (var i = 0; i < result.length; i++) {
		result[i] = isFn ? filler(i, count, result) : filler
	}
	return result
}


/**
 * 用指定的数据填充数组
 * @param  {[type]} filler [description]
 * @param  {Number} count  [description]
 * @return {[type]}        [description]
 */
function arrayFilledV2(filler, count = 1) {

	var result = new Array(count)
	if(typeof filler === 'function') {
		for (var i = 0; i < count; i++) {
			result[i] = filler(i, count, result)
		}
	} else {
		for (var i = 0; i < count; i++) {
			result[i] = filler
		}
	}

	return result
}